package com.example.administrator.yuejian35.Recommend.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.example.administrator.yuejian35.R;
import com.example.administrator.yuejian35.Recommend.adapter.GuanzhuListAdapter;
import com.example.administrator.yuejian35.Recommend.bean.Guanzhu;
import com.example.administrator.yuejian35.Recommend.model.RecommendModel;
import com.example.administrator.yuejian35.base.BaseActivity;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class GuanzhuListActivity extends AppCompatActivity {
    private RecyclerView guanzhu_rv;
    private List<Guanzhu> list;
    private String uid;
    private ImageView ic_back;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guanzhu_list);

        guanzhu_rv= (RecyclerView) findViewById(R.id.guanzhu_rv);
        ic_back= (ImageView) findViewById(R.id.video_pic);

        ic_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        uid= BaseActivity.getUserId();

        RecommendModel recommendmodel = new RecommendModel();
        Call call = recommendmodel.showguanzhu(uid);
        call.enqueue(new Callback<List<Guanzhu>>() {
            @Override
            public void onResponse(Call<List<Guanzhu>> call, Response<List<Guanzhu>> response) {
                if(GuanzhuListActivity.this!=null) {
                    list = response.body();
                    GuanzhuListAdapter adapter = new GuanzhuListAdapter(GuanzhuListActivity.this, list);
                    LinearLayoutManager layoutManager = new LinearLayoutManager(GuanzhuListActivity.this);
                    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);//Horizontal
                    guanzhu_rv.setLayoutManager(layoutManager);
                    guanzhu_rv.setAdapter(adapter);
                    guanzhu_rv.setItemAnimator(new DefaultItemAnimator());
                }
            }

            @Override
            public void onFailure(Call<List<Guanzhu>> call, Throwable t) {

            }
        });
    }
}
